package com.product.product.service.impl;

import com.product.product.domain.Product;
import com.product.product.service.ProductService;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class ProductServiceImpl implements ProductService {

    private static final Map<Integer, Product> dataMap = new HashMap<>();

    static {

        Product p1 = new Product(1 , "iphone", 9999, 10);
        Product p2 = new Product(2 , "冰箱", 9999, 20);
        Product p3 = new Product(3 , "洗衣机", 9999, 4);
        Product p4 = new Product(4 , "电视", 9999, 150);
        Product p5 = new Product(5 , "汽车", 9999, 13);

        dataMap.put(p1.getId(), p1);
        dataMap.put(p2.getId(), p2);
        dataMap.put(p3.getId(), p3);
        dataMap.put(p4.getId(), p4);
        dataMap.put(p5.getId(), p5);


    }


    @Override
    public List<Product> listProduct() {
        Collection<Product> collection = dataMap.values();
        List<Product> list = new ArrayList<>(collection);

        return list;
    }

    @Override
    public Product findById(int id) {
        return dataMap.get(id);
    }
}
